#include <bits/stdc++.h>
#define int long long
using namespace std;

int n, a[200005];
int lsta = -1, lstb = -1, ans;

void dfs(int k, int cnt)
{
    if (k > n)
    {
        ans = max(ans, cnt);
        return;
    }
    if (a[k] == lsta) dfs(k + 1, cnt + lsta);
    else
    {
        int p = lsta;
        lsta = a[k];
        dfs(k + 1, cnt);
        lsta = p;
    }
    if (a[k] == lstb) dfs(k + 1, cnt + lstb);
    else
    {
        int p = lstb;
        lstb = a[k];
        dfs(k + 1, cnt);
        lstb = p;
    }

}
signed main()
{
    freopen("color.in", "r", stdin);
    freopen("color.out", "w", stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    int t;
    cin >> t;
    while (t--)
    {
        cin >> n;
        for (int i = 1; i <= n; i++) cin >> a[i];
        ans = 0, lsta = -1, lstb = -1;
        dfs(1, 0);
        cout << ans << endl;
    }
    return 0;
}
